﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TorrentRelatedEntities;
//using MonoTorrent.BEncoding;


namespace TrackerTestProject1
{
	[TestClass]
	public class UnitTest1
	{
		static System.Globalization.CultureInfo RussianCulture = null;
		List<ServProtUser_1> InitialUsers = null;
		List<ServProtUser_1> ExpectedUsers = null;
		[AssemblyInitialize]
		public static void AssemblyInit (TestContext context)
		{
			RussianCulture = System.Globalization.CultureInfo.GetCultureInfoByIetfLanguageTag ("ru-RU");
		}
		//[ClassInitialize]
		//public static void DeleteTestUsers (TestContext context)
		//{
		//    ServProtUser_1[] Users = ServerDataInterconnect.GetUsers ();
		//    foreach (ServProtUser_1 user in Users)
		//    {
		//        if (CheckForPrefix (user.SiteUserID, TestSiteUserIDPrefix))
		//        {
		//            bool res = ServerDataInterconnect.DeleteUserBySiteUserID (user.SiteUserID);
		//            Assert.AreEqual<bool> (true, res);
		//        }
		//    }
		//}
		//[TestMethod]
		//public void GetAllUsers ()
		//{
		//    InitialUsers = ServerDataInterconnect.GetUsers ().ToList ();
		//}
		static int UserDisplayableNameCounter = 0;
		static string TestUserDisplayableNamePrefix = "Test User ";
		string GetNewTestUserDisplayableName ()
		{
			return TestUserDisplayableNamePrefix + (++UserDisplayableNameCounter);
		}
		static int UserLoginCounter = 0;
		static string TestUserLoginPrefix = "TestUser_";
		string GetNewTestUserLogin ()
		{
			return TestUserLoginPrefix + (++UserLoginCounter);
		}
		static int SiteUserIDCounter = 0;
		static string TestSiteUserIDPrefix = "TestSiteUserID_";
		string GetNewTestSiteUserID ()
		{
			return TestSiteUserIDPrefix + (++SiteUserIDCounter);
		}
		static int DownloadDisplayableNameCounter = 0;
		static string TestDownloadDisplayableNamePrefix = "Test Download ";
		string GetNewTestDownloadDisplayableName ()
		{
			return TestDownloadDisplayableNamePrefix + (++DownloadDisplayableNameCounter);
		}
		static int DownloadShortDescriptionCounter = 0;
		static string TestDownloadShortDescriptionPrefix = "Test Download Description ";
		string GetNewTestDownloadShortDescription ()
		{
			return TestDownloadShortDescriptionPrefix + (++DownloadShortDescriptionCounter);
		}
		static int SiteDownloadIDCounter = 0;
		static string TestSiteDownloadIDPrefix = "TestSiteDownloadID_";
		string GetNewTestSiteDownloadID ()
		{
			return TestSiteDownloadIDPrefix + (++SiteDownloadIDCounter);
		}
		//static Dictionary <string, string> Access = new Dictionary <string, string> ();
		static SiteAcccess Access = new SiteAcccess ();
		[ClassInitialize]
		public static void DeleteTestUsers (TestContext context)
		{
			//Access["access"] = "site";
			//Access["site-key"] = "{6E929063-E146-4ECE-AD18-5D0B41561501}";
		}

		static bool CheckForPrefix (string TestedString, string Prefix)
		{
			return TestedString.StartsWith (Prefix, true, RussianCulture);
		}
		//[TestMethod]
		//public void AddUser ()
		//{
		//    ServProtUser_1 e = new ServProtUser_1 ();
		//    e.UserName = GetNewTestUserName ();
		//    e.SiteUserID = GetNewTestSiteUserID ();
		//    ServerDataInterconnect.AddUser (e.UserName, e.SiteUserID);
		//    ServProtUser_1 a = ServerDataInterconnect.GetUserBySiteUserID (e.SiteUserID);
		//    Assert.AreEqual (e.UserName, a.UserName);
		//    Assert.AreEqual (e.SiteUserID, a.SiteUserID);
		//}
		//[TestMethod]
		//public void AddTorrent ()
		//{
		//    //ServProtUser_1 e = new ServProtUser_1 ();
		//    e.UserName = GetNewTestUserName ();
		//    e.SiteUserID = GetNewTestSiteUserID ();
		//    ServerDataInterconnect.AddUser (e.UserName, e.SiteUserID);
		//    ServProtUser_1 a = ServerDataInterconnect.GetUserBySiteUserID (e.SiteUserID);
		//    Assert.AreEqual (e.UserName, a.UserName);
		//    Assert.AreEqual (e.SiteUserID, a.SiteUserID);
		//}
		[TestMethod]
		public void AddUser ()
		{
			string SiteUserID = GetNewTestSiteUserID ();
			ServerDataInterconnect.TrackerAPIProxy.SiteAddTrackerUser (Access, SiteUserID, GetNewTestUserDisplayableName (), GetNewTestUserLogin (), "pass");
			ServerDataInterconnect.TrackerAPIProxy.SiteDeleteTrackerUser (Access, SiteUserID);
		}
		[TestMethod]
		public void AddDownload ()
		{
			string SiteDownloadID = GetNewTestSiteDownloadID ();
			ServerDataInterconnect.TrackerAPIProxy.SiteAddTrackerDownload (Access, SiteDownloadID, GetNewTestDownloadDisplayableName (), GetNewTestDownloadShortDescription ());
			ServerDataInterconnect.TrackerAPIProxy.SiteDeleteTrackerDownload (Access, SiteDownloadID);
		}
		[TestMethod]
		public void AddAssociation ()
		{
			string SiteUserID = GetNewTestSiteUserID ();
			ServerDataInterconnect.TrackerAPIProxy.SiteAddTrackerUser (Access, SiteUserID, GetNewTestUserDisplayableName (), GetNewTestUserLogin (), "pass");
			string SiteDownloadID = GetNewTestSiteDownloadID ();
			ServerDataInterconnect.TrackerAPIProxy.SiteAddTrackerDownload (Access, SiteDownloadID, GetNewTestDownloadDisplayableName (), GetNewTestDownloadShortDescription ());
			ServerDataInterconnect.TrackerAPIProxy.SiteAddTrackerUserDownloadAssociation (Access, SiteUserID, SiteDownloadID);
			ServerDataInterconnect.TrackerAPIProxy.SiteDeleteTrackerUserDownloadAssociation (Access, SiteUserID, SiteDownloadID);
			ServerDataInterconnect.TrackerAPIProxy.SiteDeleteTrackerUser (Access, SiteUserID);
			ServerDataInterconnect.TrackerAPIProxy.SiteDeleteTrackerDownload (Access, SiteDownloadID);
		}
	}
}
